/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;
import java.util.ArrayList;

public class Output extends Pin implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private CommonGate from = null;
	private ArrayList<Wire> output = new ArrayList<Wire>();

	public Output(int x, int y) {
		this.x = x -this.width-5;
		this.y = y-2;
	}
	
	public Output(){
		this.x=0;
		this.y=0;
	}

	public void setInput(CommonGate port) {
		from = port;
		this.x = x + from.width / 2;
	}
	

	public void setOutput(Wire out) {
		output.add( out);
	}
	
	public void removeOutput(int i) {
		output.remove(i);
	}
	
	public int getNumberWire(){
		return output.size();
	}

	public Wire getWire(int i) {
		return output.get(i);
	}

	public CommonGate getGate() {
		return from;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public Integer getValue(int index) {
		try {
			
			return from.getValue(index);
		}

		catch (Exception e) {
			return null;
		}

	}

	public void setNewAttributes(final int x, final int y) {
		if (from instanceof MegaInput){
		this.x = this.x+x;
		this.y = this.y +y;}
		
		else{this.x = this.x +x;
		this.y = this.y + y;}
	}

	public void draw(final Graphics g) {
		g.drawRect(this.x, this.y, width, height);
	}

}
